<?php

/**
 * This is the model class for table "budget_material".
 *
 * The followings are the available columns in table 'budget_material':
 * @property string $id
 * @property string $name
 * @property integer $main_type_id
 * @property integer $type_id
 * @property string $type_name
 * @property double $num
 * @property integer $unit_id
 * @property string $unit_name
 * @property double $ratio
 * @property string $formula
 * @property string $remark
 * @property string $create_time
 * @property string $update_time
 * @property string $created_by
 * @property string $updated_by
 * @property integer $is_delete
 */
class BudgetMaterial extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return BudgetMaterial the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'budget_material';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('name, type_name, unit_id, unit_name', 'required'),
			array('main_type_id, type_id, unit_id, is_delete', 'numerical', 'integerOnly'=>true),
			array('num, ratio', 'numerical'),
			array('name, type_name, unit_name, remark, created_by, updated_by', 'length', 'max'=>255),
			array('formula, create_time, update_time', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, name, main_type_id, type_id, type_name, num, unit_id, unit_name, ratio, formula, remark, create_time, update_time, created_by, updated_by, is_delete', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'name' => 'Name',
			'main_type_id' => 'Main Type',
			'type_id' => 'Type',
			'type_name' => 'Type Name',
			'num' => 'Num',
			'unit_id' => 'Unit',
			'unit_name' => 'Unit Name',
			'ratio' => 'Ratio',
			'formula' => 'Formula',
			'remark' => 'Remark',
			'create_time' => 'Create Time',
			'update_time' => 'Update Time',
			'created_by' => 'Created By',
			'updated_by' => 'Updated By',
			'is_delete' => 'Is Delete',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id,true);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('main_type_id',$this->main_type_id);
		$criteria->compare('type_id',$this->type_id);
		$criteria->compare('type_name',$this->type_name,true);
		$criteria->compare('num',$this->num);
		$criteria->compare('unit_id',$this->unit_id);
		$criteria->compare('unit_name',$this->unit_name,true);
		$criteria->compare('ratio',$this->ratio);
		$criteria->compare('formula',$this->formula,true);
		$criteria->compare('remark',$this->remark,true);
		$criteria->compare('create_time',$this->create_time,true);
		$criteria->compare('update_time',$this->update_time,true);
		$criteria->compare('created_by',$this->created_by,true);
		$criteria->compare('updated_by',$this->updated_by,true);
		$criteria->compare('is_delete',$this->is_delete);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}